/**
 * 微信消息详情页面js
 * 版权所有：上海戈品投资管理有限公司
 *   author king
     功能说明：微信消息详情
     创建日期：2015-10-15
     修改记录：
     备注说明：
 */

$(document).ready(function() {
	wxMsgContentList();
});


/**
 * 消息列表
 * @returns
 */
var wxMsgContentList = function(){
	
    var wxMsgId=$("#wxMsgId").val();
    var senderName=$("#senderName").val();		//用户昵称
    var reciverName=$("#reciverName").val();
    var userStyle=$("#userStyle").val();//用户类型
    var sendStatus=$("#sendStatus").val();
    var smsSendStatus=$("#smsSendStatus").val();
	
	
	var datas =  {"p":"wxMsgManage","m":"qWxMessage","wxMsgId":wxMsgId,"senderName":senderName,"reciverName":reciverName,"userStyle":userStyle,"sendStatus":sendStatus,"smsSendStatus":smsSendStatus};
	var columnDefine = {"id":"序号","senderName":"发信息操作人","receiveName":"接收者","userType":"用户类型","createTime":"消息发送时间","status":"发送状态","sms_status":"短信状态","type":"发送类型"};
	
	var formatters={
	            "createTime": function (column, rowData)
	            {
    				var newTime= new Date(rowData.createTime);
    				var rowText=newTime.getFullYear()+'-'+getTheSureTime((newTime.getMonth()+1))+'-'
    				+getTheSureTime(newTime.getDate())+' '+getTheSureTime(newTime.getHours())+':'
    				+getTheSureTime(newTime.getMinutes())+':'+getTheSureTime(newTime.getSeconds());
    				return rowText;
	            },
	            "userType": function (column, rowData)
	            {
					switch (rowData.userType) {
					case 0:
						return "用户"
						break;
					case 1:
						return "快递员"
						break;
					default:
						return ""
						break;
					}
	            },
	            "status": function (column, rowData)
	            {
					switch (rowData.status) {
					case 0:
						return "消息失败"
						break;
					case 1:
						return "消息成功"
						break;
					default:
						return ""
						break;
					}
	            },
	            "sms_status": function (column, rowData)
	            {
					if(rowData.status==0){
    					switch (rowData.sms_status) {
						case 3:
							return "短信未发"
							break;
						case 0:
							return "短信成功"
							break;
						default:
							return "短信失败"
							break;
    					}
					}else{
						return "";
					}
	            },
	            "type": function (column, rowData)
	            {
	            	switch (rowData.status) {
					case 0:
						str="多选发微信";
						break;
					case 1:
						str="给所有快递员发送消息";
						break;
					case 4:
						str="给通过审核快递员发送消息";
						break;
					case 5:
						str="给未通过审核快递员发送消息";
						break;
					case 6:
						str="给未审核快递员发送消息";
						break;
					case 2:
						str="只给用户发送消息";
						break;
					case 3:
						str="群发消息";
						break;
					default:
						break;
					}
	            }
	 };
	 var buttons =''; //操作按钮
		buttons+='<p>';
		//buttons+='<button type=\'button\' class=\'btn btn-w-m btn-info\' onclick="showMsgDetail();">查看详情</button>';
		buttons+='</p>';
	   hui.pager('service',datas ,"dataList", columnDefine , formatters , buttons ); //分页查询
	
};

function getTheSureTime(emp){
	return emp>9?emp:"0"+emp;
}

/**
 * 发送短信
 * @returns
 */
var sendSMS = function sendSMS(){
	
	var wxMsgId=$("#wxMsgId").val();
	var data={};
	
	common.showProgress();
	var url="service?p=wxMsgManage&m=sendSMS&wxMsgId="+wxMsgId;
	var rjson=common.ajaxRequest(url, data, "GET");
	common.hideProgress();
	if(rjson && rjson.result == 0){
		common.showMsg('info', '', '操作成功!');
		wxMessageList();
	}else{
		common.showMsg('error', '', '发送失败!');
	}
};



